#pragma once
// https://blog.csdn.net/zhouxuguang236/article/details/39253121

#include <algorithm>

#include <gdal_priv.h>
#include <gdalwarper.h>

using namespace std;

struct stRPCInfo {
	//double dfLONG_OFF = 0;
	//double dfLONG_SCALE = 0;
	//double dfLAT_OFF = 0;
	//double dfLAT_SCALE = 0;
	//double dfHEIGHT_OFF = 0;
	//double dfHEIGHT_SCALE = 0;
	//double* adfSAMP_NUM_COEFF;
	//double* adfSAMP_DEN_COEFF;
	//double* adfLINE_NUM_COEFF;
	//double* adfLINE_DEN_COEFF;
	//double dfSAMP_SCALE = 0;
	//double dfSAMP_OFF = 0;
	//double dfLINE_SCALE = 0;
	//double dfLINE_OFF = 0;

    double dfLINE_OFF;   /*!< Line offset */
    double dfSAMP_OFF;   /*!< Sample/Pixel offset */
    double dfLAT_OFF;    /*!< Latitude offset */
    double dfLONG_OFF;   /*!< Longitude offset */
    double dfHEIGHT_OFF; /*!< Height offset */

    double dfLINE_SCALE;   /*!< Line scale */
    double dfSAMP_SCALE;   /*!< Sample/Pixel scale */
    double dfLAT_SCALE;    /*!< Latitude scale */
    double dfLONG_SCALE;   /*!< Longitude scale */
    double dfHEIGHT_SCALE; /*!< Height scale */

    double adfLINE_NUM_COEFF[20]; /*!< Line Numerator Coefficients */
    double adfLINE_DEN_COEFF[20]; /*!< Line Denominator Coefficients */
    double adfSAMP_NUM_COEFF[20]; /*!< Sample/Pixel Numerator Coefficients */
    double adfSAMP_DEN_COEFF[20]; /*!< Sample/Pixel Denominator Coefficients */

    double dfMIN_LONG; /*!< Minimum longitude */
    double dfMIN_LAT;  /*!< Minimum latitude */
    double dfMAX_LONG; /*!< Maximum longitude */
    double dfMAX_LAT;  /*!< Maximum latitude */

};

void RPCComputeCoeffTerms(double dfLong, double dfLat, double dfHeight, double* padfTerms);
double RPCEvaluateSum(double* padfTerms, double* padfCoefs);
void RPCTransform(GDALRPCInfo* pRPC, double dfLong, double dfLat, double dfHeight, double* pdfPixel, double* pdfLine);
void RPCInverseTransform(GDALRPCInfo* pRPC, double* dbGeoTran, double dfPixel, double dfLine, double dfHeight, double* pdfLong, double* pdfLat);
bool ImageWarpRPC(const char* pszSrcFile, const char* pszDstFile, const char* pszDstWKT, double dResX, double dResY, const char* pszFormat);
